package com.crm.miaohe.controller.order;

import com.crm.miaohe.controller.PageResponse;
import com.crm.miaohe.controller.order.request.*;
import com.crm.miaohe.entity.order.OrderEntity;
import com.crm.miaohe.service.OrderService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Arrays;

@RestController
@RequestMapping("/api/erp/admin/order")
public class OrderAdminController {

    private final OrderService orderService;

    public OrderAdminController(OrderService orderService) {
        this.orderService = orderService;
    }

    @GetMapping("/list")
    public ResponseEntity<PageResponse<OrderEntity>> getOrders(@Valid OrderQueryRequest request) {
        return ResponseEntity.ok(orderService.getOrders(request));
    }


    //删除订单
    @DeleteMapping("/{orderId}")
    public  ResponseEntity<Void> deleteOrder(@PathVariable Long orderId){
        orderService.adminDeleteOrder(orderId);
        return ResponseEntity.ok().build();
    }

    @PostMapping("updateExportStatus")
    public  ResponseEntity<Void> updateExportStatus(@RequestBody OrderExportStatusRequest request){
        orderService.adminUpdateOrderExportStatus(request);
        return ResponseEntity.ok().build();
    }


    //删除订单明细
    @DeleteMapping("/details")
    public  ResponseEntity<Void> deleteOrderDetails(@RequestBody OrderDetailsRequest request){
        orderService.adminDeleteOrderDetails(request);
        return ResponseEntity.ok().build();
    }

    //删除订单明细
    @PutMapping("/details")
    public  ResponseEntity<Void> updateOrderDetails(@RequestBody OrderDetailsRequest request){
        orderService.adminUpdateOrderDetails(request);
        return ResponseEntity.ok().build();
    }

    //修改发货日期
    @PutMapping("/deliveryDate")
    public ResponseEntity<Void> auditOrders(@RequestBody OrderDeliveryDateRequest request) {
        orderService.updateDeliveryDate(request);
        return ResponseEntity.ok().build();
    }

    //修改订单备注
    @PutMapping("/orderMemo")
    public ResponseEntity<Void> auditOrders(@RequestBody OrderMemoRequest request) {
        orderService.updateOrderMemo(request);
        return ResponseEntity.ok().build();
    }

    //修改订单物流信息
    @PutMapping("/orderWuliu")
    public ResponseEntity<Void> auditOrders(@RequestBody OrderWuliuRequest request) {
        orderService.updateOrderWuliu(request);
        return ResponseEntity.ok().build();
    }
}
